package cn.sciento.boot.data.change.selector.manager;

import io.choerodon.mybatis.domain.EntityTable;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import cn.sciento.boot.data.change.selector.AbstractEntityTableSelector;
import cn.sciento.boot.data.change.selector.EntityTableSelector;
import cn.sciento.boot.data.change.selector.SqlInfo;

public abstract class EntityTableSelectorManager implements EntityTableSelector {
  private List<AbstractEntityTableSelector> entityTableSelectors;
  
  public List<AbstractEntityTableSelector> getEntityTableSelectors() {
    return this.entityTableSelectors;
  }
  
  public void setEntityTableSelectors(List<AbstractEntityTableSelector> entityTableSelectors) {
    this.entityTableSelectors = doCompose(entityTableSelectors);
  }
  
  protected abstract List<AbstractEntityTableSelector> doCompose(List<AbstractEntityTableSelector> paramList);
  
  public EntityTable getEntityTable(SqlInfo sqlInfo) {
    if (CollectionUtils.isNotEmpty(this.entityTableSelectors))
      for (EntityTableSelector entityTableSelector : this.entityTableSelectors) {
        EntityTable entityTable = entityTableSelector.getEntityTable(sqlInfo);
        if (entityTable != null)
          return entityTable; 
      }  
    return null;
  }
}
